Questions
7 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
07 / 45

What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?

Difference Between :before and ::before in CSS

In CSS, :before and ::before both target the same pseudo-element that allows content to be inserted before an element's actual content. The difference lies in the CSS specification: CSS3 introduced the double colon :: notation to clearly distinguish pseudo-elements from pseudo-classes, while : single colon syntax is retained for backward compatibility with older browsers.

Key Points
  1. 1

    :before (single colon) is the legacy syntax from CSS2, still supported for backward compatibility.

  2. 2

    ::before (double colon) is the modern CSS3 syntax, recommended for clarity and standards compliance.

  3. 3

    The double colon distinguishes pseudo-elements from pseudo-classes like :hover or :first-child.

  4. 4

    Functionally, both :before and ::before behave the same way in modern browsers.

Example: Using ::before

In this example, the star is added before the paragraph text using ::before. Using :before would achieve the same visual result, but ::before is the recommended CSS3 syntax.

Best Practices
  1. 1

    Prefer using ::before and ::after for clarity and compliance with CSS3 standards.

  2. 2

    Use the content property to define what is inserted.

  3. 3

    Test for backward compatibility if supporting older browsers that recognize only :before or :after.

  4. 4

    Use pseudo-elements for decorative or structural styling without altering HTML content.

Difficulty: 3/10
Topics: CSS pseudo-elements, selector syntax evolution, browser compatibility

Scenario Questions

0-2 years experience
  1. 1

    You're trying to add a decorative icon before a button using :before, but it's not showing up — what’s the most likely reason and how would you fix it?

  2. 2

    Your teammate used :before in the CSS, but the design system docs say to use ::before. Should you change it? Why or why not?

  3. 3

    If you write div::before { content: '★'; } and it doesn’t render, what three things would you check first?

2-5 years experience
  1. 1

    A feature using :before for tooltips broke after a CSS minifier update — the content property vanished. What’s going on, and how do you debug it?

  2. 2

    Your team’s CSS linter is flagging :before as outdated. Should you refactor all instances? What risks do you consider before doing so?

  3. 3

    You inherited a codebase with both :before and ::before used randomly. How do you decide whether to standardize, and what’s your migration plan?

5-8 years experience
  1. 1

    You’re optimizing a high-traffic page where pseudo-elements are used heavily for UI decorations — does using :before vs ::before impact rendering performance or bundle size? How would you validate that?

  2. 2

    Your component library supports legacy browsers. How do you balance modern syntax (::before) with IE11 compatibility without bloating CSS or creating maintenance debt?

  3. 3

    A third-party CSS framework uses :before internally, but your team enforces ::before. How do you handle the inconsistency without forking the library or violating accessibility?

8+ years experience
  1. 1

    You’re leading a company-wide CSS migration to modern standards. How do you prioritize refactoring pseudo-element syntax across hundreds of legacy components without breaking production?

  2. 2

    Your organization is adopting a design system with strict CSS rules. How do you architect the linting, tooling, and documentation to enforce ::before universally while managing legacy tech debt across multiple product teams?

  3. 3

    A major browser is planning to deprecate single-colon pseudo-element syntax. How do you prepare your organization’s CSS architecture for this change, and what metrics would you track to measure readiness?

Follow-up Questions

  • What happens if you use ::before in an older browser like IE8?
  • Why did the CSS spec make this change in the first place?
  • How would you enforce consistent syntax in a large codebase?